package gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JPanel;

import paint.paintCanvas;
import paint.paintPoint;
import paint.paintSnake;
import player.snakeObject;

import tag.constants;
import tag.share;

@SuppressWarnings("serial")
public class pane extends JPanel implements share,KeyListener,constants{

	
	
	public pane(){
		this.setFocusable(true);
		this.setRequestFocusEnabled(true);
		setOpaque(false);
		setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		setPreferredSize(new Dimension(frame_width,frame_height));
		addKeyListener(this);
		add(title);
		add(menu);
	}
	
	public void paintComponent(Graphics g){
		Graphics2D g2 = (Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

		paintCanvas.bg(g2);
		
		paintPoint.purple(g2);
		paintPoint.gold(g2);
		
		for(snakeObject snake : players.values())	paintSnake.snake(g2,snake);
				
	}



	public void keyPressed(KeyEvent e) {
		
	}


	public void keyReleased(KeyEvent e) {
		
		
		switch(e.getKeyCode()){
		case 80 : menu.pause(); break;
		case 27 : menu.main_menu(); break;
		}
		switch(e.getKeyCode()){
		case 39 : players.get(1).setDirectionInNextThreadInvoke(snakeObject.MOVE_RIGHT); break;
		case 37 : players.get(1).setDirectionInNextThreadInvoke(snakeObject.MOVE_LEFT); break;
		case 40 : players.get(1).setDirectionInNextThreadInvoke(snakeObject.MOVE_DOWN); break;
		case 38 : players.get(1).setDirectionInNextThreadInvoke(snakeObject.MOVE_UP); break;
		}
		
		switch(e.getKeyCode()){
		case 68 : players.get(2).setDirectionInNextThreadInvoke(snakeObject.MOVE_RIGHT); break;
		case 65 : players.get(2).setDirectionInNextThreadInvoke(snakeObject.MOVE_LEFT); break;
		case 83 : players.get(2).setDirectionInNextThreadInvoke(snakeObject.MOVE_DOWN); break;
		case 87 : players.get(2).setDirectionInNextThreadInvoke(snakeObject.MOVE_UP); break;
		}
		
	}


	public void keyTyped(KeyEvent arg0) {
	
		
	}

}
